"""
@name : mydef
@author : wenyao
@projectname: sanchuanglianxi
"""

#[1,2,3,4,5,7] -- > [1,4,9,16]
#for 循环
a = [1,2,3,4,5,6]
# b = []
# for i in a:
#     b.append(i*i)
# print(b)
#
# #列表推导式
# b = [i*i for i in a]
# #生成器表达式
# b = (i*i for i in a)

# def func(item):
#     return item*item
# result = map(func,a)
# print(list(result))
# result1 = map( lambda x:x*x ,a)
# print(list(result1))

#保留两位小数
# b = [2.6899,4.568,3.2,3.456]
# result2 = map(lambda x:round(x,2),b)
# result3 = map(lambda x:'%.2f'%x,b)
# print(list(result2))
# print(list(result3))
#转化成百分数 并且保留两位小数
# c = [0.0056,0.4532,0.5,0.71632]  #  ['0.56%','45.32%']
# result4 = map(lambda x:'%.2f%%' %(x*100),c)
# print(list(result4))

#数字转成字符串
# a = [1, 2, 3, 4, 5]
# result1 = map(lambda x: str(x), a)
# result2 = map(str,a)
# print(list(result1))
# print(list(result2))
#转ascii码
# b = "span"
# result2 = map(lambda x: ord(str(x)), b)
# result3 = map(ord,b)
# print(list(result2))
# print(list(result3))
#取绝对值
# c = [-1, -2, 0, 1, 2]
# result3 = map(lambda x: abs(x), c)
# result4 = map(abs, c)
# print(list(result4))
# print(list(result3))

###filter  获取列表中的偶数
a = [1,2,3,4,5,6,7,8]
# b = [i for i in a if i%2 ==1]
# print(b)
#
# tmp_lst = []
# for i in a :
#     if i%2 == 1:
#         tmp_lst.append(i)
# print(tmp_lst)

# def func1(x):
#     return x%2 == 1
#
# result_filter = filter(func1,a)
# print(list(result_filter))

#返回100以内的回数
#12321 从左至右  从右至左 一样
# def fi(x):
#     return str(x) == str(x)[::-1]
#     # if str(x) == str(x)[::-1]:
#     #     return True
#
# print ( list(filter(fi,range(0,100))))

#过滤出1-100以内平方根是整数的数
#math  sqrt
# from math import sqrt
# def zs(x):
#     #return sqrt(x).is_integer()
#     result = int(sqrt(x))
#     return result*result == x
# print(list(filter(zs,range(100))))

#删除空字符串
# S=['A','','B ',None,' C','    ','a',1,0]
# def N(a):
#     return a and str(a).strip()
# print(list(filter(N,S)))

#reduce
#将列表变成整数
# a = [6,7,3,4] #a = 1234  6734
# b = int("".join(map(str,a)))

# a=[6,7,3,4]  #-->6734  6*10**3
# sum=0
# for i,env in enumerate(a):
#     #print(i,env)
#     sum+=env*10**(len(a)-1-i)
# print(sum)

from functools import reduce
# a = [1,2,3,4]  #-->1234
# def func1(x,y):
#      return x*10 +y
# print(reduce(func1,a))

#第一次执行
#func1  传参  1，2  返回12
#第二次执行
#func1 传参 12，3  返回123
#第三次
#func1 传参123  返回1234
#最终程序返回1234

#阶乘  1*2*3*4
# def func2(x, y):
#     return x * y
# print(reduce(func2, a))

#a = "123.456" #转成浮点数123.456
#整数算整数，浮点数算浮点
#最好不要使用int float

#把一个"123"  转化成 123
#我们自己去实现int
# a = "123" # -- > [1,2,3]
# b = {"0":0,"1":1,"2":2,"3":3}
# def func1(x):
#     return b.get(x)
# def func2(x,y):
#     return x*10 + y
# def  str2int(a):
#     # lst = []
#     # for i in a:
#     #     lst.append(b.get(i))
#     #return reduce( lambda x,y: x*10 +y,map(func1,a))
#     return reduce(func2,map(func1,a))
# result = str2int(a)
# print(result)

#检测用户名是否符合规范
#username  ['123','wenyao']
#["123不符合规范","wenyao符合规范"]

#sorted  按照绝对值排序
# a = [36, 5, -12, 9, -21]
# b = sorted(a, key = abs)
# print(b)

#用key来指定排序规则的函数，只能传一个参数

#sorted可迭代对象的类型必须一致
# a = [1,2,3,"5"]
# >>> sorted(a)
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# TypeError: '<' not supported between instances of 'str' and 'int'

#a全为布尔型  可以排序
# >>> a = [1,True,0,False,A == B]
# >>> sorted(a)
# [0, False, False, 1, True]

#根据字符串长度排序
# >>> a =['adc','abcde','12','67bfghi']
# >>> sorted(a,key=len)
# ['12', 'adc', 'abcde', '67bfghi']

#字符串忽略大小写去排序
#['bob', 'about', 'Zoo', 'Credit']
# a = ['bob', 'about', 'Zoo', 'Credit']
# print(sorted(a,key=str.lower))

#将字符串转化为浮点数
# s = "123.456"
# def f1(x,y):
#     return x*10+y
# n = s.index('.')
# print(n)
# s1 = [i for i in s[:n]]
# print(s1)
# s2 = [i for i in s[n+1:]]
# print(s2)
# def f2(x):
#     return int(x)
# num1 = reduce(f1,map(f2,s1))
# print(num1)
# num2 = reduce(f1,map(f2,s2))
# print(num2)
# print(num1+num2/10**len(s2))

# from functools import reduce
# set1=[(str(i),i) for i in range(10)]
# print(set1)
# b=dict(set1)
# print(b)
# b['.']=0.1
# print(b)#得到字典
# temp=10;count=0;
# def fun2(x,y):
#     global temp,count
#     if y==0.1:   #当碰到小数点的时候
#         temp=1;count+=1;
#         return x
#     if count>1:
#         print("输入的数据有误")   #针对123.456.789
#         exit();
#     if temp==10:   #小数点之前的数
#         return x*temp+y
#     else:    #小数点之后的数
#         temp=temp*0.1
#         return x+y*temp
# def str22int(a):
#     return reduce(fun2,map(lambda x:b.get(x),a))
# print(str22int('123.456'))

#批量检测用户名
# import re
# print(re.findall('^[a-zA-Z_]\w{5,17}\w$',"abcedfg"))

# lst = ['wd&&&&*fr_eed','123sdeecswde','ede2','_efrfswde','edww23de']
# def guifan(n):
#     import re
#     if (re.findall('^[a-zA-Z_]\w{4,16}\w$',n)) !=[]:
#         return "{}符合规范".format(n)
#     else:
#         return "{}不符合规范".format(n)
# b = map(guifan,lst)
# print(list(b))

# lst = ['wd&&&&*fr_eed','123sdeecswde','ede2','_efrfswde','edww23de']
# def guifan(n):
#     import re
#     if (re.findall('^[a-zA-Z_]\w{4,16}\w$',n)) !=[]:
#         return True
#     else:
#         return False
# b = filter(guifan,lst)
# print(list(b))

#list  正数负数排序
# list1=[7, -8, 5, 4, 1, -2, -5]
# list2 = [False,True,False,False,False,True,True]
# #print(sorted(list1,key=lambda x:(x<0,abs(x))))
# print(sorted(list1,key=lambda x:x<0))
# print(sorted(list2))
# print(7<0)
# print(list(map(lambda x:(x<0, abs(x)),list1)))
# print(sorted(list1, key = lambda x:(x<0, abs(x))))
#[(False, 7), (True, 8), (False, 5), (False, 4), (False, 1), (True, 2), (True, 5)]
#[(False,7),(False, 5),(False, 4),(False, 1),(True, 8)]
#[(False, 1),(False, 4),.....]

# list1=[7,-8,5,4,0,-2,5]
# print(sorted(list(filter(lambda x:x>0,list1)))+sorted(list(filter(lambda x:x<0,list1)),reverse=True))
#
# list1=[7, -8, 5, 4, 1, -2, -5]
# #print(sorted(list1, key = lambda x:max(list1)-x if x<0 else x))
# print(list1)
# print(list(map(lambda x:max(list1)-x if x<0 else x,list1)))
# print(sorted(list1, key = lambda x:max(list1)-x if x<0 else x))

#字符串排序  *args  **args
zfc = 'asdf234GDSdsf23'
print(*(sorted(zfc,key = lambda x:(x.isdigit() and int(x)%2==0, x.isdigit(),x.isupper(),x.islower(),x))),sep="")
# #小写 大写  奇数 偶数
# print("".join(sorted(zfc, key=lambda x: (x.isdigit(),x.isdigit() and int(x) % 2 == 0,x.isupper(),x))))
#a (False,False,False,a)
#s (False,False,False,s)
#G (False,False,True,G)
#2 (True,True,False,2)
#3 (True,False,False,3)
#1 (True,False,False,1)
#a,s,G,1,3,2
#原理：先比较元组的第一个值，x.isdigit()是数字的为大，排在最后面，
# 是数字且是偶数的比奇数更大，大写字母比小写字母大

#字典排序
# a = {"a":1,"b":2,"c":4,"d":3}
# #按照value进行排序 最后输出一个排好序的字典
# print(next(iter(a.items())))
# print(dict(sorted(a.items(),key=lambda x:x[1])))